<template>
  <el-dialog title="签约时间历史" :visible.sync="centerDialogVisible" width="60%" center @open="getList"
             :before-close="closeDialog"
  >
    <el-form ref="searchForm" :model="searchForm" :inline="true" size="mini">
      <el-form-item label="预估签约时间" prop="begin_date">
        <el-date-picker
          v-model="searchForm.begin_date"
          type="date"
          value-format="yyyy-MM-dd"
          format="yyyy年MM月dd日"
          placeholder="选择开始日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="至" prop="end_date">
        <el-date-picker
          v-model="searchForm.end_date"
          type="date"
          value-format="yyyy-MM-dd"
          format="yyyy年MM月dd日"
          placeholder="选择结束日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button size="mini" type="primary" plain @click="search">查询</el-button>
        <el-button size="mini" type="info" plain @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="tableLoading" :data="tableData" :row-class-name="tableRowClassName" border size="mini"
              style="margin-top: 10px" max-height="600px"
    >
      <el-table-column label="预估签单额（元）" prop="quota" align="center" width="160"></el-table-column>
      <el-table-column label="成交评估" prop="transaction_evaluation" align="center" width="120"></el-table-column>
      <el-table-column label="时间" align="center" min-width="160">
        <template slot-scope="scope">
          {{ scope.row.begin_date + '~' + scope.row.end_date }}
        </template>
      </el-table-column>
      <el-table-column label="签约现金" prop="pay_cash_amount_count" align="center" width="160"></el-table-column>
      <el-table-column label="签约置换额" prop="displace_amount_count" align="center" width="160"></el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="searchForm.page"
      :page-sizes="[10,20,50,100, 200, 400]"
      :page-size.sync="searchForm.page_size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
    <span slot="footer" class="dialog-footer">
        <el-button @click="closeDialog" size="mini">关 闭</el-button>
      </span>
  </el-dialog>
</template>

<script>
import { signatureHistoryList } from '@/api/workbench/saleMonth'

export default {
  name: 'signatureHistoryDialog',
  props: {
    centerDialogVisible: {
      type: Boolean,
      default: false
    },
    customerId: {
      type: Number,
      default: -1
    }
  },
  data() {
    return {
      tableLoading: false,
      tableData: [],
      searchForm: {
        page: 1,
        page_size: 10,
        begin_date: null,
        end_date: null
      },
      listParams: {
        page: 1,
        page_size: 10,
        begin_date: null,
        end_date: null
      },
      total: 0
    }
  },
  methods: {
    handleSizeChange(val) {
      this.listParams.page_size = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listParams.page = val
      this.getList()
    },
    search() {
      this.searchForm.page = 1
      this.listParams = Object.assign({}, this.searchForm)
      this.getList()
    },
    resetForm() {
      this.$refs.searchForm.resetFields()
      this.listParams = Object.assign({}, this.searchForm)
      this.getList()
    },
    getList() {
      const params = Object.assign({}, this.listParams)
      params.customer_id = this.customerId
      this.tableLoading = true
      signatureHistoryList(params).then(res => {
        this.tableLoading = false
        this.tableData = res.data.records
        this.total = res.data.total
      })
    },
    closeDialog() {
      this.searchForm = {
        page: 1,
        page_size: 10,
        begin_date: null,
        end_date: null
      }
      this.listParams = {
        page: 1,
        page_size: 10,
        begin_date: null,
        end_date: null
      }
      this.$emit('close')
    },
    tableRowClassName({ row }) {
      if (row.invalid === 3) {
        return 'warning-row'
      } else if (row.invalid === 1) {
        return 'success-row'
      }
    }
  }
}
</script>

<style scoped lang="scss">
/deep/ .el-table .warning-row {
  background: #C0C4CC;
}

/deep/ .el-table .success-row {
  background: #f0f9eb;
}
</style>
